<?

include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

include($_SERVER['DOCUMENT_ROOT'].'/google/JSON.php');

$id = intval($_GET['portal_id']);

$sql = array();
$sql['columns'] = 'gridimage_id,user_id,realname,title,grid_reference';
$sql['wheres'] = array();
$sql['tables'][] = "p2.gridimage{$id}_bi_view";

$sql['limit'] = "5";


$query = sqlMakeQuery($sql);

$data = getAll($query);


customNoCacheHeader('',true);
customExpiresHeader(3600*24,true);

if (!empty($_GET['callback'])) {
        $callback = preg_replace('/[^\w\.-]+/','',$_GET['callback']);
        echo "{$callback}(";
}

if (count($data)) {
	
	foreach ($data as $idx => $c) {
		$data[$idx]['thumbnail'] = gGUc($c);
	}
	
	$json = new Services_JSON();
	print $json->encode($data);

} else {
	print "'error'";
}

if (!empty($_GET['callback'])) {
        echo ");";
}

